<template>
  <div style="padding-top: 10px">
    <!--页面表单/表格显示-->
    <div v-for="(item, index) in type" :key="index">
      <!--1 tab标签页切换标题-->
      <!--<Tabs :option="tabsOption" v-if="item === 'tabs'" @change="changeTabsMethods"></Tabs>-->
      <!--1 tab标签页切换内容-->
      <div v-if="item === 'tabs'" class="tabsChangeContent">
        <!--循环遍历-->
        <el-tabs v-model="tabsActiveName" @tab-click="changeTabsMethods">
          <el-tab-pane
            v-for="item1 in tabsOption.column"
            v-show="changeTabOption.prop === item1.prop"
            :key="item1.prop"
            :label="item1.label"
            :name="item1.prop"
          >
            <div
              v-for="(item2, index2) in item1.type"
              :key="item1.prop + index2"
            >
              <SimpleData
                v-if="item2 === 'simpleData'"
                :simple-data="simpleData"
                :option="simpleOption"
                :button-self="simpleButtonArray"
                @selfButton="simpleButton"
              />
              <avue-crud
                v-if="item2 === 'table'"
                :key="tabName"
                :option="tableOption"
                :data="tableData"
                :page="tablePage"
                :table-loading="loading"
                @search-change="search"
                @search-reset="searchClear"
                @size-change="sizeChangeSearch"
                @current-change="currentChangeSearch"
              >
                <template slot="searchMenu">
                  <el-button
                    v-for="(item, index) in tableButtonArray"
                    :key="'cc' + index"
                    size="small"
                    @click="tableButton(item.prop)"
                    >{{ item.label }}
                  </el-button>
                </template>
                <template slot="menu" slot-scope="scope">
                  <el-button
                    v-if="tableOption.selfMenuButton == 'msg'"
                    size="small"
                    type="text"
                    @click.native="
                      selfMenuAction(scope.row, tableOption.selfMenuButton)
                    "
                    >补发
                  </el-button>
                </template>
              </avue-crud>
              <CommonForm
                v-if="item2 === 'form'"
                :option="formOption"
                @submitForm="submitForm"
              />
            </div>
          </el-tab-pane>
        </el-tabs>
      </div>
      <!--2 simple组件-->
      <SimpleData
        v-if="item === 'simpleData'"
        :simple-data="simpleData"
        :option="simpleOption"
        :button-self="simpleButtonArray"
        @selfButton="simpleButton"
      />
      <!--3 表单组件-->
      <CommonForm
        v-if="item === 'form'"
        :option="formOption"
        @submitForm="submitForm"
      />
      <!--4 表格组件-->
      <avue-crud
        v-if="item === 'table'"
        :key="nameFlag"
        :option="tableOption"
        :data="tableData"
        :page="tablePage"
        :table-loading="loading"
        @search-change="search"
        @search-reset="searchClear"
        @sort-change="sortChange"
        @expand-change="expandChange"
        @size-change="sizeChangeSearch"
        @current-change="currentChangeSearch"
      >
        <template slot="menu" slot-scope="scope">
          <el-button
            v-for="(item, index) in tableButtonArray"
            :key="index"
            type="text"
            size="small"
            @click="contractDetail(item.prop, scope.row)"
            >{{ item.label }}
          </el-button>
        </template>
        <template slot="expand" slot-scope="{ row }">{{
          expandContent
        }}</template>
      </avue-crud>
    </div>
    <router-view />
    <!--弹框显示-->
    <el-dialog
      :title="dialogTitle"
      :visible.sync="dialogVisible"
      :close-on-click-modal="true"
      :close-on-press-escape="true"
      :show-close="true"
      top="5%"
      width="90%"
    >
      <el-scrollbar style="height: 450px">
        <avue-crud
          v-if="dialogType === 'table'"
          :key="mathRandom"
          :option="dialogTableOptions"
          :table-loading="dialogLoading"
          :data="dialogTableData"
          @search-change="dialogSearch"
          @search-reset="dialogSearchClear"
        >
          <template slot="menu" slot-scope="scope">
            <el-button
              v-for="(item, index) in dialogTableButtonArray"
              :key="index"
              size="small"
              type="text"
              @click="tableButton(item.prop, scope.row)"
              >{{ item.label }}
            </el-button>
          </template>
        </avue-crud>
        <SimpleData
          v-if="dialogType === 'simpleData'"
          :simple-data="dialogSimpleData"
          :option="dialogSimpleOptions"
          :button-self="dialogSimpleButtonArray"
          @selfButton="simpleButton"
        />
      </el-scrollbar>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="dialogTemplateConfirm"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import Tabs from "@/components/common/Tabs";
import SimpleData from "@/components/common/SimpleData";
import CommonTable from "@/components/common/CommonTable";
import CommonForm from "@/components/common/CommonDate";
import {
  queryLoss,
  sendContentMessage,
  saveTransTraffic,
} from "@/api/bankBiz/loss/loss";
import { querySelfContract, queryNoSelfContract } from "@/api/interface";

export default {
  name: "AccSearch",
  components: {
    Tabs,
    SimpleData,
    CommonTable,
    CommonForm,
  },
  data() {
    return {
      personalInfoData: {},
      tabsActiveName: "",
      namespace: "",
      nameFlag: "",
      type: [],
      waitData: true,
      // tabsData
      tabsOption: {},
      changeTabOption: {},
      // simpleData
      simpleData: {},
      simpleOption: {},
      simpleButtonArray: [],
      // tableData
      tableOption: {},
      tableData: [],
      tableTotalData: [],
      tablePage: {},
      tableButtonArray: [],
      // formData
      formOption: {},
      formButtonArray: [],
      // queryBody
      query: {
        namespace: "",
        key: "",
      },
      returnType: [],
      tabName: "",
      loading: false,
      expandContent: "",
      dialogVisible: false,
      dialogWaitData: true,
      dialogOptions: {},
      dialogTitle: "",
      dialogType: "table",
      dialogTableOptions: {},
      dialogTableData: [],
      dialogTableButtonArray: [],
      dialogSimpleOptions: {},
      dialogSimpleData: {},
      dialogSimpleButtonArray: [],
      dialogQuery: {
        namespace: "",
        key: "",
      },
      mathRandom: "",
      dialogLoading: false,
    };
  },
  created() {
    console.log("进入合同列表");
    this.initOptions();
  },
  mounted() {
    this.getCreditList();
    const self = this;
    // 收到短信银行验密结果刷新数据
    window.eventEmitter.$on("EventMsgBank", (data) => {
      if (data.p_biz == "01" && data.p_msgBankFlag == "01") {
        self.commonQueryData();
        window.globalUiKit.notify("提示", "短信银行签约成功！", "success");
      } else if (data.p_biz == "01" && data.p_msgBankFlag != "01") {
        window.globalUiKit.notify("提示", "短信银行签约失败！", "error");
      } else if (data.p_biz == "02" && data.p_msgBankFlag == "01") {
        self.commonQueryData();
        window.globalUiKit.notify("提示", "短信银行变更成功！", "success");
      } else if (data.p_biz == "02" && data.p_msgBankFlag != "01") {
        window.globalUiKit.notify("提示", "短信银行变更失败！", "error");
      } else if (data.p_biz == "03" && data.p_msgBankFlag == "01") {
        self.commonQueryData();
        window.globalUiKit.notify("提示", "短信银行关闭成功！", "success");
      } else if (data.p_biz == "03" && data.p_msgBankFlag != "01") {
        window.globalUiKit.notify("提示", "短信银行关闭失败！", "error");
      } else if (data.p_biz == "04" && data.p_msgBankFlag == "01") {
        self.commonQueryData();
        var message = "";
        if (data.p_cert_num) {
          message = data.p_cert_num
            .replace(/\\/g, "")
            .replace(/"/g, "")
            .replace(/,/g, ";");
        }
        window.globalUiKit.notify("提示", message, "success");
      } else if (data.p_biz == "04" && data.p_msgBankFlag != "01") {
        window.globalUiKit.notify("提示", "短信银行一键关闭失败！", "error");
      }
    });
    // 收到查询密码业务结果刷新数据
    window.eventEmitter.$on("EventPassUpdate", (data) => {
      if (data.p_pass_operate == "02" && data.p_msgBankFlag == "01") {
        self.commonQueryData();
        window.globalUiKit.notify("提示", "查询密码设置成功！", "success");
      } else if (data.p_pass_operate == "02" && data.p_msgBankFlag != "01") {
        window.globalUiKit.notify("提示", "查询密码设置失败！", "error");
      } else if (data.p_pass_operate == "03" && data.p_msgBankFlag == "01") {
        self.commonQueryData();
        window.globalUiKit.notify("提示", "查询密码重置成功！", "success");
      } else if (data.p_pass_operate == "03" && data.p_msgBankFlag != "01") {
        window.globalUiKit.notify("提示", "查询密码重置失败！", "error");
      } else if (data.p_pass_operate == "04" && data.p_msgBankFlag == "01") {
        self.commonQueryData();
        window.globalUiKit.notify("提示", "查询密码修改成功！", "success");
      } else if (data.p_pass_operate == "04" && data.p_msgBankFlag != "01") {
        window.globalUiKit.notify("提示", "查询密码修改失败！", "error");
      }
    });
  },
  beforeDestroy() {
    window.eventEmitter.$off("EventMsgBank");
    window.eventEmitter.$off("EventPassUpdate");
  },
  methods: {
    // 获取合同列表
    getCreditList() {
      const data = sessionStorage.getItem("personalInfoData");
      this.personalInfoData = JSON.parse(data);
      //给table赋值
      this.tableData = this.personalInfoData.contrDetailList;
      console.log("合同列表信息==", this.tableData);
      this.tablePage.total = this.tableData.length;
      this.tableTotalData = this.tableData;
      // 兼容客户端分页
      if (window.Settings.pageType == "Client") {
        this.tableData = this.tableTotalData.slice(
          (this.tablePage.currentPage - 1) * this.tablePage.pageSize,
          this.tablePage.currentPage * this.tablePage.pageSize
        );
        this.tablePage.total = this.tableTotalData.length;
        return;
      }
    },
    // 查看合同详情
    contractDetail(prop, row) {
      console.log("查看合同详情", prop, row);
      const data = {
        mobileNo: this.personalInfoData.mobileNo,
        contrNbr: row.contrNbr,
      };
      if (prop === "personal-customeBuss-details") {
        // 自营合同
        if (row.isProprietary == 0) {
          querySelfContract(data).then((res) => {
            if (res.data.code == "200") {
              const contractDetail = res.data.data;
              sessionStorage.setItem(
                "contractDetail",
                JSON.stringify(contractDetail)
              );
              sessionStorage.setItem(
                "isProprietary",
                JSON.stringify(row.isProprietary)
              );
              this.$router.push({
                name: "bussDetail",
              });
            } else if (res.data.code == "201") {
              window.globalUiKit.notify("提示", res.data.message, "info");
            } else {
              window.globalUiKit.notify("提示", res.data.message, "info");
            }
          });
        } else {
          // 非自营合同
          queryNoSelfContract(data).then((res) => {
            const contractDetail = res.data.data;
            sessionStorage.setItem(
              "contractDetail",
              JSON.stringify(contractDetail)
            );
            sessionStorage.setItem(
              "isProprietary",
              JSON.stringify(row.isProprietary)
            );
            this.$router.push({
              name: "unBussDetail",
            });
          });
        }
      }
    },
    // 初始化配置
    initOptions() {
      this.namespace = this.$route.path.split("/")[1];
      // 首字母大写
      this.namespace =
        this.namespace.substring(0, 1).toUpperCase() +
        this.namespace.substring(1);
      this.nameFlag = this.$route.path.split("/")[2];
      if (!this.nameFlag) {
        console.log("nameFlag is not exist!");
        return;
      }
      this.type = this.$route.meta.type;
      // console.log("type===",this.type);
      this.returnType = this.$route.meta.type;
      this.waitData = this.$route.meta.waitData;
      console.log(
        "receive params is: " + this.namespace + ", " + this.nameFlag
      );
      let commonOptions = "";
      if (this.namespace === "Personal") {
        commonOptions = personalOptions;
        // window.personalOptions.moduleOption.accountOption.checkedFlag = false
      } else if (this.namespace === "Company") {
        commonOptions = companyOptions;
        // window.personalOptions.moduleOption.accountOption.checkedFlag = false
      } else if (this.namespace === "PublicInfo") {
        commonOptions = publicOptions;
      } else if (this.namespace === "ReportLoss") {
        commonOptions = personalOptions;
      }
      // 循环组件，初始化赋值
      for (let i = 0; i < this.type.length; i++) {
        // 1 页签初始化
        if (this.type[i] === "tabs") {
          const tabsViewOption = commonOptions.tabsViewOption;
          this.tabsOption = tabsViewOption[this.nameFlag].tabsOption;
          // 默认第一个页签
          this.tabsActiveName = this.tabsOption.column[0].prop;
          this.changeTabOption.prop = this.tabsOption.column[0].prop;
          this.returnType = this.tabsOption.column[0].type;
          this.waitData = this.tabsOption.column[0].waitData;
          this.dialogOptions = this.tabsOption.column[0].detailOptions;
          // 初始化第一个页签配置
          for (let j = 0; j < this.tabsOption.column[0].type.length; j++) {
            if (this.tabsOption.column[0].type[j] == "table") {
              this.tableOption = this.tabsOption.column[0].tableOptions;
              this.tablePage = this.tabsOption.column[0].tablePage;
              this.tableButtonArray =
                this.tabsOption.column[0].tableButtonArray;
            } else if (this.tabsOption.column[0].type[j] == "simpleData") {
              this.simpleOption = this.tabsOption.column[0].simpleOptions;
              this.simpleButtonArray =
                this.tabsOption.column[0].simpleButtonArray;
            } else if (this.tabsOption.column[0].type[j] == "form") {
              this.formOption = this.tabsOption.column[0].formOptions;
              this.formButtonArray = this.tabsOption.column[0].formButtonArray;
            }
          }

          if (this.tabsOption.column[0].query) {
            this.query.query = Object.assign(
              {},
              this.tabsOption.column[0].query
            );
          }
          this.query.namespace = this.namespace;
          this.query.key = this.tabsOption.column[0].prop;
        }
        // 2 表单初始化
        else if (this.type[i] === "form") {
          const formViewOption = commonOptions.formViewOption;
          this.formOption = formViewOption[this.nameFlag].formOptions;
          this.formButtonArray = formViewOption[this.nameFlag].formButtonArray;
          if (formViewOption[this.nameFlag].query) {
            this.query.query = Object.assign(
              {},
              formViewOption[this.nameFlag].query
            );
          }
          this.query.namespace = this.namespace;
          this.query.key = this.nameFlag;
        }
        // 3 表格初始化
        else if (this.type[i] === "table") {
          const tableViewOption = commonOptions.tableViewOption;
          this.tableOption = tableViewOption[this.nameFlag].tableOptions;
          this.waitData = tableViewOption[this.nameFlag].waitData;
          this.tablePage = tableViewOption[this.nameFlag].tablePage;
          this.tableButtonArray =
            tableViewOption[this.nameFlag].tableButtonArray;
          if (tableViewOption[this.nameFlag].query) {
            this.query.query = Object.assign(
              {},
              tableViewOption[this.nameFlag].query
            );
          }
          this.query.namespace = this.namespace;
          this.query.key = this.nameFlag;
          this.query.query = {
            // 'pageSize': this.query.query.pageSize,
            // 'currentPage': this.query.query.currentPage
          };
        }
        // 4 simple初始化
        else if (this.type[i] === "simpleData") {
          const simpleViewOption = commonOptions.simpleViewOption;
          this.simpleButtonArray =
            simpleViewOption[this.nameFlag].simpleButtonArray;
          this.simpleOption = simpleViewOption[this.nameFlag].simpleOptions;
          if (simpleViewOption[this.nameFlag].query) {
            this.query.query = Object.assign(
              {},
              simpleViewOption[this.nameFlag].query
            );
          }
          this.query.namespace = this.namespace;
          this.query.key = this.nameFlag;
        }
      }
      // this.commonQueryData(this.waitData)
    },
    // 切换页签
    changeTabsMethods(tab, event) {
      console.log(tab, event);
      this.tabName = tab.name;
      let data = [];
      for (let i = 0; i < this.tabsOption.column.length; i++) {
        if (this.tabsOption.column[i].prop === this.tabsActiveName) {
          data = this.tabsOption.column[i];
        }
      }
      this.changeTabOption = data;
      if (data.query) {
        this.query.query = Object.assign({}, data.query);
      }
      this.query.key = data.prop;
      this.returnType = data.type;
      this.dialogOptions = data.detailOptions;
      for (let i = 0; i < data.type.length; i++) {
        if (data.type[i] == "table") {
          this.tableOption = data.tableOptions;
          this.tablePage = data.tablePage;
          this.tableButtonArray = data.tableButtonArray;
          this.tableData = [];
          this.tableTotalData = [];
        } else if (data.type[i] == "simpleData") {
          this.simpleOption = data.simpleOptions;
          this.simpleButtonArray = data.simpleButtonArray;
        } else if (data.type[i] == "form") {
          this.formOption = data.formOptions;
          this.formButtonArray = data.formButtonArray;
        }
      }
      this.commonQueryData();
    },
    // 公用组件接口
    commonQueryData(waitData) {
      if (waitData) {
        return;
      }
      console.log("公用组件接口");
      // loading
      this.loading = true;
      // 卡号/账户号
      if (this.namespace != "PublicInfo") {
        this.query.query.accountNo =
          sessionStorage.getItem("bankNo") ||
          this.$store.getters.GET_GLOBALCARDNO;
        if (!this.query.query.accountNo) {
          window.globalUiKit.notify(
            "提示",
            "暂未获取到卡号，请返回到交易首页重新进入子交易！",
            "error"
          );
          return;
        }
      }
      // 汇率查询-汇率日期
      if (this.query.query.exchangeRateDateSearch) {
        const exchangeRateDate = this.query.query.exchangeRateDateSearch;
        this.query.query.exchangeRateDate = [
          exchangeRateDate,
          exchangeRateDate,
        ];
      }
      // 存款利率查询
      if (this.query.key == "depositInterestRateInquiry") {
        // 默认币种为人民币
        if (!this.query.query.currency) {
          this.query.query.currency = "11";
        }
        // 存款方式为大额存单
        if (this.query.query.depositMethod != "110") {
          delete this.query.query.area;
        }
      }
      // 查询密码修改
      else if (this.query.key == "passUpdate") {
        this.query.query.accountNo = sessionStorage.getItem("customerNo");
      }
      // 初始化分页参数
      this.query.query.currentPage = 1;
      this.query.query.pageSize = 20;
      this.tablePage.currentPage = 1;
      this.tablePage.pageSize = 20;
      this.tablePage.total = 0;
      // 调用公共业务接口
      queryLoss(this.query)
        .then((res) => {
          console.log("response data is: " + JSON.stringify(res.data));
          this.loading = false;
          if (res.data.code == 200) {
            for (let i = 0; i < this.returnType.length; i++) {
              if (this.returnType[i] == "table") {
                if (
                  res.data.data.resList == null ||
                  res.data.data.resList == undefined
                ) {
                  this.tableData = [];
                  this.tableTotalData = [];
                  this.tablePage.total = 0;
                  return;
                }
                this.tableData = res.data.data.resList;
                this.tableTotalData = res.data.data.resList;
                // 个人理财产品、理财产品超市、当前持有、当前委托、基金产品超市
                if (
                  this.query.key == "personalProductSupermarket" ||
                  this.query.key == "wealthProductSupermarket" ||
                  this.query.key == "wealthCurrentHeld" ||
                  this.query.key == "wealthCurrentTrust" ||
                  this.query.key == "fundProductSupermarket"
                ) {
                  console.log(parseInt(res.data.data.totalNum));
                  this.tablePage.total = parseInt(res.data.data.totalNum);
                  return;
                }
                // 兼容客户端分页
                if (window.Settings.pageType == "Client") {
                  this.tableData = this.tableTotalData.slice(
                    (this.tablePage.currentPage - 1) * this.tablePage.pageSize,
                    this.tablePage.currentPage * this.tablePage.pageSize
                  );
                  this.tablePage.total = this.tableTotalData.length;
                }
              } else if (this.returnType[i] == "simpleData") {
                this.simpleData = res.data.data;
                console.log("key is: " + this.query.key);
                if (this.query.key == "messageService") {
                  // 短信银行 0 未开通，1 已开通
                  if (this.simpleData.status == "0") {
                    this.simpleButtonArray[0].hide =
                      !window.Settings.msgServiceSwitch;
                    this.simpleButtonArray[1].hide = true;
                    this.simpleButtonArray[2].hide = true;
                    this.simpleButtonArray[3].hide = true;
                    this.simpleButtonArray[4].hide = true;
                  } else {
                    this.simpleButtonArray[0].hide = true;
                    this.simpleButtonArray[1].hide =
                      !window.Settings.msgServiceSwitch;
                    this.simpleButtonArray[2].hide =
                      !window.Settings.msgServiceSwitch;
                    this.simpleButtonArray[3].hide =
                      !window.Settings.msgServiceSwitch;
                    this.simpleButtonArray[4].hide = false;
                  }
                } else if (this.query.key == "passUpdate") {
                  // 短信银行 0 未开通，1 已开通
                  if (this.simpleData.passStatus == "0") {
                    this.simpleButtonArray[0].hide = false;
                    this.simpleButtonArray[1].hide = true;
                    this.simpleButtonArray[2].hide = true;
                  } else {
                    this.simpleButtonArray[0].hide = true;
                    this.simpleButtonArray[1].hide = false;
                    this.simpleButtonArray[2].hide = false;
                  }
                }
              } else if (this.returnType[i] == "form") {
              }
            }
            saveTransTraffic(
              this.query.namespace + "-" + this.query.key,
              "成功",
              ""
            );
          } else {
            const errMsg = res.data.message;
            window.globalUiKit.notify("提示", errMsg, "error");
            saveTransTraffic(
              this.query.namespace + "-" + this.query.key,
              "失败",
              errMsg
            );
            this.simpleData = {};
            this.tableData = [];
            this.tableTotalData = [];
            this.tablePage.total = 0;
          }
        })
        .catch((err) => {
          saveTransTraffic(
            this.query.namespace + "-" + this.query.key,
            "失败",
            ""
          );
          this.loading = false;
          this.simpleData = {};
          this.tableData = [];
          this.tableTotalData = [];
          this.tablePage.total = 0;
          console.log(err);
        });
    },
    searchData(sel) {
      console.log("sel is: " + sel);
      this.selectData = sel;
    },
    // 搜索
    search(params, done) {
      console.log("search conditions params is：" + JSON.stringify(params));
      this.getListByKey(params, done);
    },
    // 表格自定按钮事件
    tableButton(prop, row) {
      console.log("prop is: " + prop + ", row is: " + JSON.stringify(row));
      // 最近10笔
      if (prop === "personal-customeBuss-details") {
        if (row.number === 1) {
          this.$router.push({
            name: "bussDetail",
          });
        } else {
          this.$router.push({
            name: "unBussDetail",
          });
        }
      }
      // 短信银行业务-重发
      else if (prop == "personal-messageService-sendMsg") {
        this.$confirm(row.sms_content, "短信发送", {
          confirmButtonText: "发送",
          cancelButtonText: "取消",
          type: "",
        })
          .then(() => {
            const params = {
              content: row.sms_content,
              phone: row.phone,
              agentName: Constants.Agent.agentName,
              agentId: Constants.Agent.agentId,
              smsType: "综合业务",
            };
            sendContentMessage(params)
              .then((res) => {
                if (res.data.code == 200) {
                  window.globalUiKit.notify(
                    "提示",
                    "短信发送成功！",
                    "success"
                  );
                } else {
                  window.globalUiKit.alert(
                    "短信发送失败",
                    "失败原因：" +
                      res.data.message +
                      "；入参：" +
                      JSON.stringify(params)
                  );
                }
              })
              .catch((error) => {
                console.log(error);
                window.globalUiKit.alert(
                  "短信发送失败",
                  "失败原因：" + error + "；入参：" + JSON.stringify(params)
                );
              });
          })
          .catch(() => {
            console.log("取消发送！");
          });
      }
    },
    // simpleData自定义事件
    simpleButton(prop) {
      console.log("prop is: " + prop);
      // 开户行及预留手机号码查询
      if (prop == "personal-telReservationData-sendMsg") {
        const params = {
          content:
            "尊敬的客户您好，您的开户行信息如下，开户行名称：" +
            this.simpleData.openBankName +
            "；开户行地址：" +
            this.simpleData.address +
            "；大额行号：" +
            this.simpleData.largeNum +
            "；开户行电话：" +
            this.simpleData.phone +
            "；预留手机号：" +
            this.simpleData.telReservation,
          phone: this.simpleData.telReservation,
          agentName: Constants.Agent.agentName,
          agentId: Constants.Agent.agentId,
          smsType: "综合业务",
        };
        sendContentMessage(params)
          .then((response) => {
            if (response.data.code == 200) {
              console.log("send message success");
            }
          })
          .catch((error) => {
            console.log(error);
          });
      }
      // 短信银行签约
      else if (prop == "personal-messageService-set") {
        if (!sessionStorage.getItem("bankNo")) {
          window.globalUiKit.notify(
            "提示",
            "获取卡号信息为空，不能发起签约请求！",
            "error"
          );
          return;
        }
        const userdata = {
          // 私有部分，根据不同验证类型组合
          p_verifytype: "02", // 验密类型
          p_cert_type: "01", // 介质类型
          p_cert_num: sessionStorage.getItem("bankNo") || "", // 介质号码
          p_accno: "", // 对公客户号
          p_oper_id: "", // 对公操作员ID
          p_pass_type: "01", // 密码类型
          p_pass_operate: "01", // 交易密码操作
          p_biz: "01", // 业务操作
          // 公共部分
          r_function: "singletransfer",
          r_flag: "3",
          con_flag: "1",
        };
        globalUserData.verifyPass(userdata);
      }
      // 短信银行变更
      else if (prop == "personal-messageService-change") {
        if (!sessionStorage.getItem("bankNo")) {
          window.globalUiKit.notify(
            "提示",
            "获取卡号信息为空，不能发起变更请求！",
            "error"
          );
          return;
        }
        const userdata = {
          // 私有部分，根据不同验证类型组合
          p_verifytype: "02", // 验密类型
          p_cert_type: "01", // 介质类型
          p_cert_num: sessionStorage.getItem("bankNo") || "", // 介质号码
          p_accno: "", // 对公客户号
          p_oper_id: "", // 对公操作员ID
          p_pass_type: "01", // 密码类型
          p_pass_operate: "01", // 交易密码操作
          p_biz: "02", // 业务操作
          // 公共部分
          r_function: "singletransfer",
          r_flag: "3",
          con_flag: "1",
        };
        globalUserData.verifyPass(userdata);
      }
      // 短信银行关闭
      else if (prop == "personal-messageService-close") {
        if (!sessionStorage.getItem("bankNo")) {
          window.globalUiKit.notify(
            "提示",
            "获取卡号信息为空，不能发起关闭请求！",
            "error"
          );
          return;
        }
        const userdata = {
          // 私有部分，根据不同验证类型组合
          p_verifytype: "02", // 验密类型
          p_cert_type: "01", // 介质类型
          p_cert_num: sessionStorage.getItem("bankNo") || "", // 介质号码
          p_accno: "", // 对公客户号
          p_oper_id: "", // 对公操作员ID
          p_pass_type: "01", // 密码类型
          p_pass_operate: "01", // 交易密码操作
          p_biz: "03", // 业务操作
          // 公共部分
          r_function: "singletransfer",
          r_flag: "3",
          con_flag: "1",
        };
        globalUserData.verifyPass(userdata);
      }
      // 短信银行一键关闭
      else if (prop == "personal-messageService-oneClickClose") {
        if (!sessionStorage.getItem("bankNoList")) {
          window.globalUiKit.notify(
            "提示",
            "获取卡号信息为空，不能发起一键关闭请求！",
            "error"
          );
          return;
        }
        const userdata = {
          // 私有部分，根据不同验证类型组合
          p_verifytype: "02", // 验密类型
          p_cert_type: "05", // 介质类型
          p_cert_num: sessionStorage.getItem("bankNoList") || "", // 介质号码
          p_accno: "", // 对公客户号
          p_oper_id: "", // 对公操作员ID
          p_pass_type: "01", // 密码类型
          p_pass_operate: "01", // 交易密码操作
          p_biz: "04", // 业务操作
          // 公共部分
          r_function: "singletransfer",
          r_flag: "3",
          con_flag: "1",
        };
        globalUserData.verifyPass(userdata);
      }
      // 短信银行重发短信
      else if (prop == "personal-messageService-resend") {
        this.dialogTemplate("messageServerResend");
      }
      // 查询密码设置
      else if (prop == "personal-passUpdate-set") {
        if (!sessionStorage.getItem("bankNo")) {
          window.globalUiKit.notify(
            "提示",
            "获取卡号信息为空，不能发起密码设置请求！",
            "error"
          );
          return;
        }
        const userdata = {
          // 私有部分，根据不同验证类型组合
          p_verifytype: "02", // 验密类型
          p_cert_type: "01", // 介质类型
          p_cert_num: sessionStorage.getItem("bankNo") || "", // 介质号码
          p_accno: "", // 对公客户号
          p_oper_id: "", // 对公操作员ID
          p_pass_type: "02", // 密码类型
          p_pass_operate: "02", // 交易密码操作
          p_biz: "00", // 业务操作
          // 公共部分
          r_function: "singletransfer",
          r_flag: "3",
          con_flag: "1",
        };
        globalUserData.verifyPass(userdata);
      }
      // 查询密码重置
      else if (prop == "personal-passUpdate-reset") {
        if (!sessionStorage.getItem("bankNo")) {
          window.globalUiKit.notify(
            "提示",
            "获取卡号信息为空，不能发起密码重置请求！",
            "error"
          );
          return;
        }
        const userdata = {
          // 私有部分，根据不同验证类型组合
          p_verifytype: "02", // 验密类型
          p_cert_type: "01", // 介质类型
          p_cert_num: sessionStorage.getItem("bankNo") || "", // 介质号码
          p_accno: "", // 对公客户号
          p_oper_id: "", // 对公操作员ID
          p_pass_type: "02", // 密码类型
          p_pass_operate: "03", // 交易密码操作
          p_biz: "00", // 业务操作
          // 公共部分
          r_function: "singletransfer",
          r_flag: "3",
          con_flag: "1",
        };
        globalUserData.verifyPass(userdata);
      }
      // 查询密码修改
      else if (prop == "personal-passUpdate-update") {
        if (!sessionStorage.getItem("bankNo")) {
          window.globalUiKit.notify(
            "提示",
            "获取卡号信息为空，不能发起密码修改请求！",
            "error"
          );
          return;
        }
        const userdata = {
          // 私有部分，根据不同验证类型组合
          p_verifytype: "02", // 验密类型
          p_cert_type: "01", // 介质类型
          p_cert_num: sessionStorage.getItem("bankNo") || "", // 介质号码
          p_accno: "", // 对公客户号
          p_oper_id: "", // 对公操作员ID
          p_pass_type: "02", // 密码类型
          p_pass_operate: "04", // 交易密码操作
          p_biz: "00", // 业务操作
          // 公共部分
          r_function: "singletransfer",
          r_flag: "3",
          con_flag: "1",
        };
        globalUserData.verifyPass(userdata);
      }
    },
    // 表单自定义按钮事件
    formButton(prop) {
      buttonAction.selfFunHandler(prop);
    },
    // 切换行数
    sizeChangeSearch(val) {
      this.query.query.currentPage = 1;
      this.query.query.pageSize = val;
      // 个人理财产品、理财产品超市、当前持有、当前委托、基金产品超市
      if (
        this.query.key == "personalProductSupermarket" ||
        this.query.key == "wealthProductSupermarket" ||
        this.query.key == "wealthCurrentHeld" ||
        this.query.key == "wealthCurrentTrust" ||
        this.query.key == "fundProductSupermarket"
      ) {
        queryLoss(this.query)
          .then((res) => {
            this.tablePage.total = parseInt(res.data.data.totalNum);
            this.tableData = res.data.data.resList;
          })
          .catch((err) => {
            console.log(err);
          });
        return;
      }
      // 兼容客户端分页
      if (window.Settings.pageType == "Client") {
        this.tablePage.currentPage = 1;
        this.tablePage.pageSize = val;
        this.tableData = this.tableTotalData.slice(
          (this.tablePage.currentPage - 1) * this.tablePage.pageSize,
          this.tablePage.currentPage * this.tablePage.pageSize
        );
        this.tablePage.total = this.tableTotalData.length;
        return;
      }
    },
    // 切换页码
    currentChangeSearch(val) {
      this.query.query.currentPage = val;
      console.log("切换页码");
      // 个人理财产品、理财产品超市、当前持有、当前委托、基金产品超市
      if (
        this.query.key == "personalProductSupermarket" ||
        this.query.key == "wealthProductSupermarket" ||
        this.query.key == "wealthCurrentHeld" ||
        this.query.key == "wealthCurrentTrust" ||
        this.query.key == "fundProductSupermarket"
      ) {
        queryLoss(this.query)
          .then((res) => {
            this.tablePage.total = parseInt(res.data.data.totalNum);
            this.tableData = res.data.data.resList;
          })
          .catch((err) => {
            console.log(err);
          });
        return;
      }
      // 兼容客户端分页
      if (window.Settings.pageType == "Client") {
        this.tablePage.currentPage = val;
        this.tableData = this.tableTotalData.slice(
          (this.tablePage.currentPage - 1) * this.tablePage.pageSize,
          this.tablePage.currentPage * this.tablePage.pageSize
        );
        this.tablePage.total = this.tableTotalData.length;
        return;
      }
    },
    // 搜索条件清空回调
    searchClear() {
      this.query.query = {
        pageSize: 20,
        currentPage: 1,
      };
    },
    // 表单提交
    submitForm(data, done) {
      this.$message.success("当前数据" + JSON.stringify(data));
      this.commonQueryData();
      if (done) {
        done();
      }
    },
    // 表格搜索查询
    getListByKey(params, done) {
      if (this.query.key == "detailSearchData") {
        this.query.query.count = "";
        this.query.query.transferDate = [
          new Date(new Date().setDate(new Date().getDate() - 90)).Format(
            "yyyyMMdd"
          ),
          new Date().Format("yyyyMMdd"),
        ];
        this.query.query.accountNo = sessionStorage.getItem("bankNo");
        if (params && params.transferDate) {
          // 交易日期范围不能超过一年
          if (this.query.namespace === "Personal") {
            if (
              Utils.dateRange(params.transferDate[0], params.transferDate[1]) >
              365
            ) {
              window.globalUiKit.notify(
                "提示",
                "交易日期范围不能超过一年！",
                "error"
              );
              done();
              return;
            }
          } else {
            if (
              Utils.dateRange(params.transferDate[0], params.transferDate[1]) >
              90
            ) {
              window.globalUiKit.notify(
                "提示",
                "交易日期范围不能超过三个月！",
                "error"
              );
              done();
              return;
            }
          }
          // 交易日期开始时间不能超过五年
          if (
            Utils.dateRange(
              params.transferDate[0],
              new Date().Format("yyyyMMdd")
            ) > 1826
          ) {
            window.globalUiKit.notify(
              "提示",
              "交易日期开始时间不能超过五年！",
              "error"
            );
            done();
            return;
          }
        }
      }
      if (this.query.key == "depositInterestRateInquiry") {
        this.query.query.currency = "";
        this.query.query.depositMethod = "";
      }
      Object.keys(params).forEach((keys) => {
        if (params[keys]) {
          this.query.query[keys] = params[keys];
        }
      });
      this.commonQueryData();
      if (done) {
        done();
      }
    },
    // 表格排序
    sortChange(row) {
      console.log(JSON.stringify(row));
      // 金融信息-理财产品超市
      if (this.query.key == "wealthProductSupermarket") {
        this.query.query = {
          currentPage: 1,
          pageSize: 20,
        };
        // 升序(ascending)、降序(descending)、无序(null)
        if (row.order == "descending" || row.order == null) {
          this.query.query[row.prop] = 0;
        } else {
          this.query.query[row.prop] = 1;
        }
        this.commonQueryData();
      }
    },
    // 行展开
    expandChange(row, expendList) {
      this.expandContent = "";
      this.tableOption.expandRowKeys = [];
      if (expendList.length && row) {
        this.tableOption.expandRowKeys.push(row.productCode);
        const params = {
          namespace: this.namespace,
          key: "productInstruction",
          query: {
            productCode: row.productCode,
          },
        };
        queryLoss(params)
          .then((res) => {
            if (
              res.data.code == 200 &&
              res.data.data &&
              res.data.data.content
            ) {
              this.expandContent = Utils.filterText(res.data.data.content);
            } else {
              window.globalUiKit.notify("提示", "暂无内容信息！", "error");
            }
          })
          .catch((err) => {
            console.log(err);
          });
      }
    },
    /** **************************************** 弹框详情相关 ***********************************/
    // 弹框dialog模板渲染
    dialogTemplate(nameFlag) {
      // 清空数据变量
      // 重新初始化数据
      this.dialogVisible = true;
      this.mathRandom = Math.random() * 10;
      this.dialogTitle = this.dialogOptions[nameFlag].title;
      this.dialogWaitData = this.dialogOptions[nameFlag].waitData;
      for (let j = 0; j < this.dialogOptions[nameFlag].type.length; j++) {
        this.dialogType = this.dialogOptions[nameFlag].type[j];
        if (this.dialogOptions[nameFlag].type[j] == "table") {
          this.dialogTableOptions = this.dialogOptions[nameFlag].tableOptions;
          this.dialogTableButtonArray =
            this.dialogOptions[nameFlag].tableButtonArray;
        } else if (this.dialogOptions[nameFlag].type[j] == "simpleData") {
          this.dialogSimpleOptions = this.dialogOptions[nameFlag].simpleOptions;
          this.dialogSimpleButtonArray =
            this.dialogOptions[nameFlag].simpleButtonArray;
        }
      }
      this.dialogQuery.namespace = this.namespace;
      this.dialogQuery.key = this.dialogOptions[nameFlag].prop;
      this.dialogQuery.query = Object.assign(
        {},
        this.dialogOptions[nameFlag].query
      );
      this.commonDetailQueryData(this.dialogWaitData);
    },
    dialogTemplateConfirm() {
      this.dialogVisible = false;
      this.dialogQuery.query = {};
    },
    // 详情搜索
    dialogSearch(params, done) {
      console.log("detail params: " + JSON.stringify(params));
      // 短信重发
      if (this.dialogQuery.key == "messageServiceListData") {
        this.dialogQuery.query.transferDate = [
          new Date().Format("yyyyMMdd"),
          new Date().Format("yyyyMMdd"),
        ];
      }
      Object.keys(params).forEach((keys) => {
        if (params[keys]) {
          this.dialogQuery.query[keys] = params[keys];
        }
      });
      this.commonDetailQueryData();
      if (done) {
        done();
      }
    },
    // 详情清空
    dialogSearchClear() {
      this.dialogQuery.query = {};
    },
    // 调用详情弹框接口
    commonDetailQueryData(dialogWaitData) {
      if (dialogWaitData) {
        return;
      }
      // loading加载
      this.dialogLoading = true;
      if (this.dialogQuery.key == "messageServiceListData") {
        this.dialogQuery.query.phone = sessionStorage.getItem("customerPhone");
      }
      queryLoss(this.dialogQuery)
        .then((res) => {
          this.dialogLoading = false;
          if (this.dialogType == "table") {
            this.dialogTableData = res.data.data.resList;
          } else if (this.dialogType == "simpleData") {
            this.dialogSimpleData = res.data.data;
          }
        })
        .catch((err) => {
          console.log(err);
          this.dialogLoading = false;
        });
    },
    // 初始化页面配置
    clearOption() {
      this.namespace = "";
      this.nameFlag = "";
      this.type = [];
      this.waitData = true;
      // tabsData
      this.tabsOption = {};
      this.changeTabOption = {};
      // simpleData
      this.simpleData = {};
      this.simpleOption = {};
      this.simpleButtonArray = [];
      // tableData
      this.tableOption = {};
      this.tableData = [];
      this.tablePage = {};
      this.tableButtonArray = [];
      // tableData
      this.formOption = {};
      this.formButtonArray = [];
      // queryBody
      this.query = {
        namespace: "",
        key: "",
      };
      this.returnType = [];
      this.expandContent = "";
      this.dialogType = "table";
      this.dialogVisible = false;
      this.dialogWaitData = true;
      this.dialogOptions = {};
      this.dialogTitle = "";
      this.dialogTableOptions = {};
      this.dialogTableData = [];
      this.dialogTableButtonArray = [];
      this.dialogSimpleOptions = {};
      this.dialogSimpleData = {};
      this.dialogSimpleButtonArray = [];
      this.dialogQuery = {
        namespace: "",
        key: "",
      };
    },
    // 自定义菜单
    selfMenuAction(row, selfProp) {
      // 短信补发
      if (selfProp == "msg") {
        console.log("msg row is: " + JSON.stringify(row));
      }
    },
  },
  // 当前组件路由守卫
  beforeRouteEnter(to, from, next) {
    to.meta.currentComponentFlag = true;
    next();
  },
  beforeRouteLeave(to, from, next) {
    this.$destroy();
    next();
  },
  // 初始化, TODO 优化，是否keep alive
  // watch: {
  //   '$route'(to, from) {
  //    访问当前组件，且上一次访问路径与本次访问路径不同
  //    if (to.meta.currentComponentFlag && this.cachePath !== to.path) {
  //       this.clearOption()
  //       this.initOptions()
  //       this.cachePath = to.path
  //     }
  //   }
  // }
};
</script>

<style scoped>
.avue-crud.avue-crud__menu {
  display: inline !important;
}
</style>
